﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assets.entities {
    public struct MarchingSquare {

        private BitArray _bits;
        private byte _type;

        public MarchingSquare(bool topLeft, bool topRight, bool bottomRight, bool bottomLeft){
            this._bits = new BitArray(new bool[4]{bottomLeft, bottomRight, topRight, topLeft});

            byte[] bytes = new byte[1];
            this._bits.CopyTo(bytes, 0);
            this._type = bytes[0];
        }

        public byte type {
            get {
                return this._type;
            }
        }

        public bool topLeftBit {
            get {
                return this._bits.Get(3);
            }
        }

        public bool topRightBit {
            get {
                return this._bits.Get(2);
            }
        }

        public bool bottomRightBit {
            get {
                return this._bits.Get(1);
            }
        }

        public bool bottomLeftBit {
            get {
                return this._bits.Get(0);
            }
        }

        public bool isEmpty {
            get {
                return this._type == 0;
            }
        }

        public bool isFull {
            get {
                return this._type == 15;
            }
        }

        public bool isIsoline {
            get {
                return !this.isEmpty && !this.isFull;
            }
        }

        public string ToString() {
            StringBuilder sb = new StringBuilder();
            foreach (var b in this._bits) {
                sb.Append((bool)b ? "1" : "0");
            }
            return sb.ToString();
        }
    }
}
